package com.kongzue.baseokhttpv3.slice;


import com.kongzue.baseokhttp.util.JsonList;
import com.kongzue.baseokhttp.util.JsonMap;
import com.kongzue.baseokhttpv3.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.agp.components.*;


public class ListAdapter extends BaseItemProvider {
    private AbilitySlice slice;

    private JsonList jsonList;

    public ListAdapter(AbilitySlice slice, JsonList jsonList) {
        this.slice = slice;
        this.jsonList = jsonList;
    }

    @Override
    public int getCount() {
        return jsonList.size();
    }

    @Override
    public Object getItem(int i) {
        return i;
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public Component getComponent(int i, Component component,
                                  ComponentContainer componentContainer) {
        DirectionalLayout layout = (DirectionalLayout) LayoutScatter.getInstance(slice).parse(
                ResourceTable.Layout_item_list, null, false);
        Text des = (Text) layout.findComponentById(ResourceTable.Id_txt_list);
        des.setText(((JsonMap) jsonList.get(i)).getString("title"));
        return layout;
    }

}
